package com.example.agricultural_machinery_navigation.utils;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/*****
 * 类名：SpaceItemDecoration
 * 功能：RecyclerView.Item设置的参数类
 *
 * ******/

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    public SpaceItemDecoration(int space) {
        this.space = space;
    }

    /***
     * 方法名：getItemOffsets
     * @param outRect 每个item格子容器
     * @param parent item的父容器
     * @param view  item的布局
     * @param state item的状态
     *
     * ***/
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //不是第一个的格子都设一个左边和底部的间距
        outRect.left = space;
        outRect.bottom = space;
        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        if (parent.getChildLayoutPosition(view) %3==0) {
            outRect.left = 0;
        }
    }

}